package junior.util.wrap;

import java.io.Serializable;

/**
 * 封装3个对象
 * 
 * @param <A>
 * @param <B>
 * @param <C>
 * @author ZhangXiaoye
 * @date 2016年10月6日 上午9:17:10
 */
public class Tuple3<A, B, C> implements Serializable, Tuple{

	/** 说明  */
	private static final long serialVersionUID = 1L;

	public final A _0;
	
	public final B _1;
	
	public final C _2;
	
	public Tuple3(A a, B b, C c){
		this._0 = a;
		this._1 = b;
		this._2 = c;
	}

	public A getA() {
		return _0;
	}

	public B getB() {
		return _1;
	}

	public C getC() {
		return _2;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((_0 == null) ? 0 : _0.hashCode());
		result = prime * result + ((_1 == null) ? 0 : _1.hashCode());
		result = prime * result + ((_2 == null) ? 0 : _2.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof Tuple3)) {
			return false;
		}
		@SuppressWarnings("rawtypes")
		Tuple3 other = (Tuple3) obj;
		if (_0 == null) {
			if (other._0 != null) {
				return false;
			}
		} else if (!_0.equals(other._0)) {
			return false;
		}
		if (_1 == null) {
			if (other._1 != null) {
				return false;
			}
		} else if (!_1.equals(other._1)) {
			return false;
		}
		if (_2 == null) {
			if (other._2 != null) {
				return false;
			}
		} else if (!_2.equals(other._2)) {
			return false;
		}
		return true;
	}
	
	@Override
	public String toString(){
		return "Tuple(" + _0 + ", " + _1 + ", " + _2 + ")";
	}
	
	@Override
	public int size() {
		return 3;
	}

	@Override
	public Object get(int i) {
		switch(i){
		case 0:
			return _0;
		case 1:
			return _1;
		case 2:
			return _2;
		default:
			throw new IndexOutOfBoundsException("i must between [0, 2], but got " + i);
		}
	}
}
